﻿using System.IO;
using System.Security.Cryptography;

namespace PhiStore.Experiments.Encryption
{
    class GenericEncryption
    {
        public static Stream Encrypt(Stream input, ICryptoTransform encrypter)
        {
            input.Position = 0;
            MemoryStream output = new MemoryStream();
            CryptoStream crypto = new CryptoStream(output, encrypter, CryptoStreamMode.Write);
            byte[] buffer = new byte[4096];

            ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(input, crypto, buffer);
            crypto.FlushFinalBlock();

            return output;
        }
        public static Stream Decrypt(Stream input, ICryptoTransform decrypter)
        {
            MemoryStream output = new MemoryStream();

            CryptoStream crypto = new CryptoStream(input, decrypter, CryptoStreamMode.Read);
            byte[] buffer = new byte[4096];
            ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(crypto, output, buffer);

            return output;
        }
    }
}
